package cn.xiaohuodui.rest.notify;

import cn.xiaohuodui.util.XMLParser;
import com.alipay.bean.AliPayNotifyForm;
import com.tecent.weixin.mp.bean.PayNotifyData;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.*;

/**
 * Author :chenqisheng
 * Date   :16/5/3.
 */
@RestController
@RequestMapping("/notify")
public class OrderNotifyApi {
    private final Logger logger = Logger.getLogger(OrderNotifyApi.class);

    //支付宝支付完成回调入口
    @RequestMapping(value = "/alipayNotify", method = RequestMethod.POST)
    public void payCompleteNotify(@ModelAttribute AliPayNotifyForm alipayNotifyForm) {
        if (alipayNotifyForm.getTrade_status().equals("TRADE_SUCCESS")) {//付款成功完成后，支付宝系统发送该交易状态通知
            logger.info("支付宝支付成功" + alipayNotifyForm.toString());
        } else {
            logger.info("支付宝支付失败" + alipayNotifyForm.toString());
        }
    }

    //微信支付完成回调入口
    @RequestMapping(value = "/wxPayNofity", method = RequestMethod.POST)
    public void payCompleteNotify(@RequestBody String result) {
        PayNotifyData payNotifyData = XMLParser.getObjectFromXML(result, PayNotifyData.class);
        if (payNotifyData.getResult_code().equals("SUCCESS")) {
            logger.info("微信支付成功" + result.toString());
        } else {
            logger.info("微信支付失败:" + result.toString());
        }
    }
}
